https://stackoverflow.com/questions/41906091/custom-distribution-in-pymc3-specific-example
In [2]:
import pymc3 as mc
import numpy as np
import matplotlib.pyplot as plt
In [7]:
import numpy as np
import pymc3 as pm
with pm.Model() as model:
dist = pm.Mixture('dist', np.array([0.25, 0.75]),
[pm.Uniform.dist(-0.15, -0.05), pm.Uniform.dist(0., 0.05)])
N = 40000
samples = dist.random(size=N)
In [10]:
plt.hist(samples, 100, density=True);
In [19]:
with pm.Model():
mu = pm.Normal('mu',0,1)
normal_dist = pm.Normal.dist(mu, 1)
pm.DensityDist('density_dist', normal_dist.logp, )
trace = pm.sample(10000)
In [20]:
pm.traceplot(trace, combined=True)
Out[20]:
In [23]:
with pm.Model():
# mu = pm.Normal('mu',0,1)
norm = scipy.stats.norm()
# normal_dist = pm.Normal.dist(mu, 1)
pm.DensityDist('density_dist', norm.logpdf, )
trace = pm.sample(10000)
pm.traceplot(trace, combined=True)
In [ ]:
In [ ]: